package com.cloudstreamservice8002.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloudstreamservice8002.entity.DeliveryProcess;
import com.cloudstreamservice8002.mapper.DeliveryProcessMapper;
import com.cloudstreamservice8002.service.DeliveryProcessService;
import com.google.common.base.Preconditions;
import org.springframework.stereotype.Service;

/**
* @author 26407
* @description 针对表【delivery_process】的数据库操作Service实现
* @createDate 2025-06-11 00:42:49
*/
@Service
public class DeliveryProcessServiceImpl extends ServiceImpl<DeliveryProcessMapper, DeliveryProcess>
        implements DeliveryProcessService {

    @Override
    public IPage<DeliveryProcess> getDeliveryProcessList(Integer pageNum, Integer pageSize, Long deliveryId) {
        IPage<DeliveryProcess> page = new Page<>(pageNum, pageSize);
        if(deliveryId == null){
            return this.page(page);
        }
        return this.page(page, new QueryWrapper<DeliveryProcess>().eq("delivery_id", deliveryId));
    }

    @Override
    public Boolean create(DeliveryProcess deliveryProcess) {
        Preconditions.checkArgument(deliveryProcess.getDeliveryId() != null, "配送单ID不能为空");
        //判断配送步骤是否已经存在
        if (this.count(new QueryWrapper<DeliveryProcess>().eq("delivery_id", deliveryProcess.getDeliveryId()).eq("process_step", deliveryProcess.getProcessStep())) > 0) {
            throw new IllegalArgumentException("配送步骤已经存在");
        }
        return this.save(deliveryProcess);
    }

    @Override
    public Boolean updates(DeliveryProcess deliveryProcess) {
        Preconditions.checkArgument(deliveryProcess.getId() != null, "id不能为空");
        return this.updateById(deliveryProcess);
    }

    @Override
    public boolean removeDeliveryId(Long deliveryId) {
        return this.remove(new QueryWrapper<DeliveryProcess>().eq("delivery_id", deliveryId));
    }
}






